草庐IT

IT 设备

全部标签

c++ - 在 switch 语句中使用类类型 : is it better than using typeid operator?

我在下面看到了有关C++标准$6.4.2中switch语句的内容。Switch语句可以带一个条件。Theconditionshallbeofintegraltype,enumerationtype,orofaclasstypeforwhichasingleconversionfunctiontointegralorenumerationtypeexists(12.3).Iftheconditionisofclasstype,theconditionisconvertedbycallingthatconversionfunction,andtheresultoftheconversion

c++ - 在设备上的线性内存中循环二维数组时将 float* 转换为 char*

在CUDA4.0编程指南的第21页有一个示例(下面给出)来说明循环遍历设备内存中二维float组的元素。2D的尺寸是width*height//Hostcodeintwidth=64,height=64;float*devPtr;size_tpitch;cudaMallocPitch(&devPtr,&pitch,width*sizeof(float),height);MyKernel>>(devPtr,pitch,width,height);//Devicecode__global__voidMyKernel(float*devPtr,size_tpitch,intwidth,int

c++ - 两阶段查找 : is it possible to easily mix inheritence and templates

简介:C++标准区分依赖模板参数的符号名称和不依赖模板参数的名称,这称为两阶段名称查找(参见here)。定义模板时,会尽快解析非相关名称。另一方面,从属名称仅在模板实例化时解析。示例:templatestructBase{typedefTtype;staticconstintn=3;virtualintf()=0;intf(intx){returnx*2;}};//doesn'tcompile!templatestructDerived:Base{typefield;//Thecompilerdoesn'tknowBase::typeyet!intf(){returnn;}//thec

c++ - int8_t 和 char : converts between pointers to integer types with different sign - but it doesn't

我正在处理一些嵌入式代码,并且正在从头开始编写一些新东西,因此我更愿意坚持使用uint8_t、int8_t等类型。然而,当移植一个函数时:voidfunctionName(char*data)到:voidfunctionName(int8_t*data)在将文字字符串传递给函数时,我收到编译器警告“在指向具有不同符号的整数类型的指针之间转换”。(即调用functionName("putthistextin");时)。现在,我明白了为什么会发生这种情况,并且这些行只是调试,但我想知道人们认为什么是最合适的处理方式,而不是对每个文字字符串进行类型转换。在实践中,我不认为一揽子类型转换比使用

c++ - 从 cuda 内核访问类数据成员——如何设计适当的主机/设备交互?

我一直在尝试将一些cuda/C代码转换成更面向对象的代码,但以我目前对cuda功能机制的理解,我的目标似乎并不容易实现。对于这种情况,我也找不到很好的解释。毕竟这可能是不可能的。我有一个global类myClass的对象,它包含一个要填充到内核中的数组。myClass中的方法应该如何定义,以便数组和bool成员从设备可见,然后数组可以复制回主机?我使用的是cuda7.5,我的卡的计算能力是3.5。这是描述情况的暂定结构:#include#include#includeclassmyClass{public:boolbool_var;//Setfromhostandreadablefro

c++ - 未对齐的内存访问 : is it defined behavior or not?

这个问题在这里已经有了答案:Whatdoesthestandardsayaboutunalignedmemoryaccess?(1个回答)关闭4年前。考虑以下代码:#includeintmain(){char*c=newchar('a');charac[4]={'a','b','c','d'};unsignedlonglongint*u=reinterpret_cast(c);unsignedlonglongint*uc=reinterpret_cast(&ac[3]);*u=42;*uc=42;std::cout这是否被视为有效代码,还是内存泄漏/未定义行为?我在问,因为通过:*u=

c++ - Visual Studio 2010 中的多进程构建 : Worth it?

我已经开始使用VS2010测试我们的C++软件,构建时间非常糟糕(30-45分钟,大约是VS2005时间的两倍)。我一直在阅读有关多进程编译的/MP开关。不幸的是,它与我们经常使用的一些功能不兼容,例如#import、增量编译和预编译header。您是否有一个类似的项目,您在关闭预编译头文件之类的东西后尝试了/MP开关?您获得更快的构建了吗?我的机器在具有4GBRAM和快速SSD存储的4核机器上运行64位Windows7。病毒扫描程序已禁用,软件环境非常简单。编辑:Martin和jdehaan指出MP与预编译header并非不兼容。详情为here. 最佳答案

c++ - hash_map : why it defines less, 而不是 equal_to

C++,使用VisualStudio2010。关于为什么hash_map的用户定义特征的问题实际上需要总排序。我有一个简单的结构,比如说FOO,它只有一些整数。我想使用hash_map,这是一个哈希表,其键无序,用于存储FOO的结构。.我只需要快速搜索它的关联值,所以这是一个正确的选择:hash_map.但是,我需要为FOO实现自己的哈希函数和一些比较函数.这是hash_map的定义,摘自MSDN:template>,classAllocator=allocator>>classhash_map原来我需要实现hash_compare仿函数:template>classhash_comp

STM32 CubeMX USB_MSC(存储设备U盘)

STM32CubeMXSTM32CubeMXUSB_MSC(存储设备U盘)STM32CubeMX前言《使用内部Flash》——U盘一、STM32CubeMX设置USB时钟设置USB使能UBS功能选择FATFS功能二、代码部分修改代码"usbd_storage_if.c"修改代码"user_diskio.c"main函数初始化插上USB实验效果《SPI_SD卡》——U盘前言STM32CubeMX配置USB将STM32设置可以作为存储设备或者IAP升级功能《使用内部Flash》——U盘一、STM32CubeMX设置USB时钟设置USB使能UBS功能选择要注意:stm32f103c8t6内部Flas

C++ : Read a file name from the command line and utilize it in my file

如何从命令行读取文件名并在我的C++代码文件中使用它?例如:./cppfileinputFilenameoutputFilename非常感谢任何帮助! 最佳答案 intmain(intargc,char**argv){stringinFile="";stringoutFile="";if(argc==3){inFile=argv[1];outFile=argv[2];}else{cout 关于C++:Readafilenamefromthecommandlineandutilizeiti